<?php
class Accione extends AppModel {
	var $name = 'Accione';
	var $displayField = 'descripcion';		
	
	function generateCodigo(){
		$result = $this->query('select 
									COALESCE(cast(max(d.codigo) as integer)+1,1) as "Accione__codigo" 
								from expedientes.acciones d 
								where d.activo = true');
		$result = $result[0];
		return str_repeat('0',4-strlen($result['Accione']['codigo'])).$result['Accione']['codigo'];			
	}	
}
?>